package com.example.manualManagement.service.impl.user.account;

import com.example.manualManagement.entity.Manage;
import com.example.manualManagement.service.impl.UserDetailsImpl;
import com.example.manualManagement.service.user.account.InfoService;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class InfoServiceImpl implements InfoService {
    @Override
    public Map<String, String> getinfo() {
        UsernamePasswordAuthenticationToken authenticationToken =
                (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();

        UserDetailsImpl loginUser = (UserDetailsImpl) authenticationToken.getPrincipal();
        Manage manage = loginUser.getManage();

        Map<String, String> map = new HashMap<>();
        map.put("error_massage", "success");
        map.put("userId", manage.getUserid().toString());
        map.put("userName", manage.getUsername());
        map.put("userPassword", manage.getUserpassword());

        return map;
    }
}
